Skip to content

Conversation

steveklabnik
Copy link
Contributor

This is a little short, but the FFI guide needs a cohesive go-over, and this at least adds the information in the meantime.

It also modernizes the style in a small way, by moving the tilde syntax to the grave syntax.

@steveklabnik steveklabnik changed the title Gh10489 Add an example to the FFI guide Dec 18, 2014
The `extern "C"` makes this function adhere to the C calling convention, as
discussed above in "[Foreign Calling
Conventions](guide-ffi.html#foreign-calling-conventions)". The `no_mangle`
attribute turns of Rust's name mangling, so that this function can be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/of/off/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅


```
#[no_mangle]
pub extern "C" fn hello_rust() -> *const u8 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to drop the "C" wherever possible as it's the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. @aturon do we have any convention here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aturon says no official one, but:

steve@warmachine:~/src/rust$ git grep 'extern {' | wc -l
253
steve@warmachine:~/src/rust$ git grep 'extern "C" {' | wc -l
25

So, seems legit. :)

@emberian
Copy link
Contributor

emberian commented Jan 5, 2015

@steveklabnik ping

@steveklabnik
Copy link
Contributor Author

This has now been updated to be on the book, and I fixed the style issue. @alexcrichton r?

}
```

The `extern "C"` makes this function adhere to the C calling convention, as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/"C"//

@steveklabnik
Copy link
Contributor Author

@alexcrichton both nits fixed

bors added a commit that referenced this pull request Jan 17, 2015
Add an example to the FFI guide

Reviewed-by: alexcrichton
bors added a commit that referenced this pull request Jan 17, 2015
Add an example to the FFI guide

Reviewed-by: alexcrichton
@steveklabnik
Copy link
Contributor Author

Doing this manually as part of #21300

@steveklabnik steveklabnik deleted the gh10489 branch October 25, 2017 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants